package com.wnxy.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wnxy.admin.common.ResponseResult;
import com.wnxy.admin.dto.AuthorizationDto;
import com.wnxy.admin.dto.StaffRoleDto;
import com.wnxy.admin.entity.RolePermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;

import com.wnxy.admin.entity.StaffRole;
import com.wnxy.admin.service.IStaffRoleService;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 员工角色中间表 前端控制器
 * </p>
 *
 * @author All
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/staff-role")
public class StaffRoleController {

    private final IStaffRoleService staffRoleServiceImpl;
    public StaffRoleController(IStaffRoleService staffRoleServiceImpl){
        this.staffRoleServiceImpl = staffRoleServiceImpl;
    }

    @GetMapping("/getById")
    public ResponseResult getById(Integer id){
       return ResponseResult.ok(staffRoleServiceImpl.getAll(id));
    }

//    @GetMapping("/queryStaffByRoleId")
//    public ResponseResult queryStaffByRoleId(Integer id){
//        List<StaffRole> list = staffRoleServiceImpl
//                .list(Wrappers.lambdaQuery(StaffRole.class)
//                        .eq(StaffRole::getRoleId,id));
//        //只筛选出所有的员工id
//        List<Integer> ids = list.stream().map(e -> e.getStaffId()).collect(Collectors.toList());
//        return ResponseResult.ok(ids);
//    }

    @PostMapping("/authorizationStaff")
    public ResponseResult authorizationStaff(@RequestBody StaffRoleDto staffRoleDto){
        staffRoleServiceImpl.authorizationStaff(staffRoleDto);
        return ResponseResult.ok();
    }

}
